﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace Soul.Expressions
{
    public class LambdaOptions
    {
        private readonly List<MethodInfo> methods = new List<MethodInfo>();
        private readonly List<ParameterExpression> parameters = new List<ParameterExpression>();

        public void AddParameter<T>(string name)
        {
            AddParameter(name, typeof(T));
        }

        public void AddParameter(string name, Type type)
        {
            parameters.Add(Expression.Parameter(type, name));
        }

        public void AddFunction(MethodInfo method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            methods.Add(method);
        }

        public void AddFunction<T>()
        {
            var methods = typeof(T).GetMethods().Where(a => a.IsStatic).ToList();
            foreach (var item in methods)
            {
                AddFunction(item);
            }
        }

        internal IEnumerable<MethodInfo> Methods => methods;

        internal IEnumerable<ParameterExpression> Parameters => parameters;

    }
}
